package com.xsz.controller;

import com.xsz.entity.Meeting;
import com.xsz.entity.User;
import com.xsz.service.MeetingService;
import com.xsz.util.KeyUtil;
import com.xsz.util.MD5Utils;
import com.xsz.util.ResultVOUtil;
import com.xsz.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("meeting")
public class MeetingController {
    @Resource
    MeetingService meetingService;

    @PostMapping("/create")
    public String add(String title,String address,String startTime,String[] vehicle) {
        //存入会议信息
        try{
        Meeting meeting=new Meeting();
        meeting.setTitle(title);
        meeting.setAddress(address);
        meeting.setStartTime(startTime);
        meeting.setId(KeyUtil.getId());
        String people = vehicle[0];
        for(int i=1;i<vehicle.length;i++){
            people=people+";"+vehicle[i];
        }
        meeting.setPeople(people);
        ResultVOUtil.success(meetingService.add(meeting));
        } catch(NullPointerException e){
            e.printStackTrace();
        }catch(Exception e){
            e.printStackTrace();
        }
        return "redirect:/meeting/showAll";
    }

    @RequestMapping("/showAll")
    public String selectAll(Model model) {
        List<Meeting> a1=meetingService.getAll();
        model.addAttribute("a1",a1);
        return "/index";
    }

//    @RequestMapping("/selectByNamw")
//    public String selectByNamw(Model model) {
//            List<Meeting> a2=meetingService.getByName("第1次会议");
//            model.addAttribute("a2",a2);
//            return "/index2";
//}


    @RequestMapping("/findALL")
    @ResponseBody
    public List<Meeting> findAll(){
        List<Meeting> list = meetingService.getAll();
        return list;
    }

    @RequestMapping("/index")
    public  String index(){
        return "/index2";
    }
}
